<template>
  <div class="content">
    <table class="table-goods" v-if="order">
      <colgroup>
        <col name="col01" width="480">
        <col name="col04" width="160">
        <col name="col05" width="200">
      </colgroup>
      <thead>
      <tr>
        <th class="col01">商品</th>
        <th class="col04">金额</th>
        <th class="col05">操作</th>
      </tr>
      </thead>
      <tbody>
      <tr
        v-for="(item,index) in order"
        :key="index">
        <td class="col01 one-line" title="七喜柠檬味碳酸饮料整箱330ml*24促销装">
          <img class="thumbnail-goods" :src=imgSrc>&nbsp;
          七喜柠檬味碳酸饮料整箱330ml*24促销装
        </td>
        <td class="col02">43.90</td>
        <td class="col05">
          <span v-if="order[index]=='0'" class="btn-text" @click="drop(index)">付款</span>
          <span v-if="order[index]=='1'" class="btn-text" >已支付</span>
          <span v-if="order[index]=='2'" class="btn-text" >已取消</span>
        </td>
      </tr>
      </tbody>
    </table>
    <div class="placeholder" v-else>当前并无订单！快去下单吧~~</div>
  </div>
</template>

<script>
  export default {
    name: 'Cart',
    data () {
      return {
        order: {1: 0, 2: 0},
        cart: [],
        imgSrc: './static/images/qixi01.jpg',
        timer: null
      }
    },
    mounted () {
      this.$nextTick(function () {
        this.getStore()
      })
      this.timer = setInterval(() => {
        let url = 'http://127.0.0.1:8777/get'
        this.axios.get(url).then((res) => {
          this.order = res.data
          console.log(this.order[1])
        })
      }, 1000)
    },
    methods: {
      getStore () {
      },
      setStore () {
      },
      drop (index) {
        let url = 'http://127.0.0.1:8777/pay?orderId=' + index
        this.axios.get(url).then((res) => {
          url = 'http://127.0.0.1:8777/get'
          this.axios.get(url).then((res) => {
            this.order = res.data
          })
        })
      }
    }
  }
</script>

<style scoped>
  .content {
    width: 1120px;
    margin-left: auto;
    margin-right: auto;
  }
  .one-line {
    word-break: break-all;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  .table-goods {
    width: 100%;
    margin-top: 15px;
    color: #555;
    table-layout: fixed;
    border-collapse: collapse;
    user-select: none;
    cursor: default;
  }
  .table-goods>tbody>tr {
    transition: background-color 200ms linear;
    border-top: 1px solid #ebeef5;
  }
  .table-goods>tbody>tr:last-child {
    border-bottom: 1px solid #ebeef5;
  }
  .table-goods>tbody>tr:hover {
    background-color: rgba(149, 191, 103, .1);
  }
  .table-goods th,
  .table-goods td {
    text-align: left;
    font-size: 16px;
    padding-left: 12px;
  }
  .table-goods th {
    line-height: 52px;
  }
  .table-goods td {
    line-height: 120px;
  }
  .thumbnail-goods {
    width: 100px;
    vertical-align: middle;
  }
  .btn-text {
    color: #409eff;
    font-size: 14px;
    cursor: pointer;
  }
  .placeholder {
    color: #555;
    line-height: 80px;
    font-size: 24px;
  }
</style>
